#!/bin/bash

# Updates the local development TRALE by applying the patches from the
# repository to the local original TRALE.

# location of local copy of trale-sld repository trunk, e.g.
# /home/ke/workspace/trale-sld
TRUNK=${TRALESLD_TRUNK_DIR:?"Please set this environment variable."}

# location of TRALE-under-development, e.g.
# /home/ke/opt/trale
DEV=${TRALESLD_TRALE_DEV_DIR:?"Please set this environment variable."}

# location of original TRALE from Toronto repository, e.g.
# /home/ke/opt/trale.orig
ORIG=${TRALESLD_TRALE_ORIG_DIR:?"Please set this environment variable."}

if [ ${PATSCH_FORCE:-no} = yes ]
then
  ANSWER=yes
else
  read -p "Really overwrite development copy of TRALE (answer yes/no)? " ANSWER
fi

if [ ${ANSWER} = yes ]
then
  for file in trale startup.pl ghooks.pl debugger/interp.pl
  do
    patch $ORIG/$file $TRUNK/trale/$file.diff -o $DEV/$file
    touch $TRUNK/trale/$file.diff
  done

  for file in debugger/tralesld_hooks.pl
  do
    cp $TRUNK/trale/$file $DEV/$file
    touch $TRUNK/trale/$file
  done
fi
